﻿/*------------------------------------------------------------
 * Author : Tharinduni Udugamasuriya
 * FinCon dll for Handeling DB 
 * RegistryController : Registry Read/ Write Management - inner
 -----------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Win32;

namespace DSPL.Contracts
{
    class RegistryController
    {
        string root ="Software\\FINACGLOBAL\\";

        public string Read(string KeyName)
        {
            try
            {
                RegistryKey masterKey = Registry.LocalMachine.OpenSubKey(root, false);

                if (masterKey == null)
                {
                    return null;
                }
                else
                {
                    return (string)masterKey.GetValue(KeyName.ToUpper());


                }
            }
            catch (Exception e)
            {
                return null;
                throw e; 
            }
        }

        public bool Write(string KeyName, object Value)
        {
            try
            {
                RegistryKey masterKey = Registry.LocalMachine.CreateSubKey(root);
                if (masterKey!=null)
                {
                    masterKey.SetValue(KeyName, Value);
                    return true;
                }               

                return true;
            }
            catch (Exception e)
            {
                return false;
                throw e;                
            }
        }
    }
}
